﻿using System;
using System.Collections.Generic;
using Model;

namespace BusinessObject
{
    public class SprintBO : Repository<Sprint>
    {
        #region Singleton

        private static readonly SprintBO _instance = new SprintBO();

        /// <summary>
        /// Instância do objeto singleton.
        /// </summary>
        public static SprintBO Instance
        {
            get { return _instance; }
        }

        private SprintBO() { }

        #endregion Singleton

        public void InsertSprint(Release release, string name, DateTime startDate, DateTime endDate)
        {
            Sprint sprint = new Sprint();

            sprint.Nome = name;
            sprint.DataInicio = startDate;
            sprint.DataFim = endDate;
            sprint.Release = release;

            SprintBO.Instance.Save(sprint);
        }

        public bool CheckDates(Release release, DateTime startDate, DateTime endDate)
        {
            if (((release.DataInicio <= startDate) && (startDate <= release.DataFim)) && ((release.DataInicio <= endDate) && (endDate <= release.DataFim)) && (startDate <= endDate))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public IList<Sprint> GetSprintByProject(Project project)
        {
            IList<Sprint> lista = base.GetByCriteria(s => s.Release.Project.Id == project.Id);
            return lista;
        }

        public IList<Sprint> GetSprintByRelease(Release release)
        {
            IList<Sprint> lista = base.GetByCriteria(s => s.Release.Id == release.Id);
            return lista;
        }

        public IList<Sprint> GetSprintByProjectByDate(Project project, DateTime date)
        {
            IList<Sprint> lista = base.GetByCriteria(s => s.Release.Project.Id == project.Id && s.DataInicio >= date);
            return lista;
        }
    }
}